{
  function add(x, y) {
    return x + y
  }
  var numbers = [4, 38]
  console.log(add (...numbers)) // 4
}

{
  function f(v, w, x, y, z) {}
  var args = [0, 1]
  f(-1, ...args, 2, ...[3]) 
}

{
  const max = Math.max.apply(this, [14, 3, 77])
  console.log(max) // 77
  const max2 = Math.max(...[14, 3, 77])
  console.log(max2) // 77
}

{
  let arr1 = [0, 1, 2]
  let arr2 = [3, 4, 5]
  arr1.push(...arr2)
  console.log(arr1) // [0, 1, 2, 3, 4, 5]
}

{
  let arr1 = ['a', 'b']
  let arr2 = ['c']
  let arr3 = ['d', 'e']
  // ES5 的合并数组
  let con1 = arr1.concat(arr2, arr3)
  console.log('con1', con1) // [ 'a', 'b', 'c', 'd', 'e' ]
  // ES6合并数组
  let con2 = [...arr1, ...arr2, ...arr3]
  console.log('con2', con2) // [ 'a', 'b', 'c', 'd', 'e' ]
}


{
  const [first, ...rest] = [1, 2, 3, 4, 5]
  console.log('first', first) // 1
  console.log('rest', rest) // [2, 3, 4, 5]
}

{
  try {
    // const [first, ...middle, last] = [1, 2, 3, 4, 5]
    //报错  Rest element must be last element
    // console.log('first', first)
    // console.log('middle', middle)
    // console.log('last', last)
  } catch(err) {
    // console.log(err)
  }
}

{
  function dataFilelds () {
    return [2019, 10, 22]
  }
  var d = new Date(...dataFilelds())
  console.log(d.toDateString()) // Fri Nov 22 2019
}

{
  console.log([...'hello']) // [ 'h', 'e', 'l', 'l', 'o' ]
}

{
  let arrayLike = {
    0: 'a',
    '1': 'b',
    '2': 'c',
    length: 3
  }
  let arr = Array.from(arrayLike)
  console.log('arr', arr) // [ 'a', 'b', 'c' ]
}

{
  console.log(Array.from('hello')) // [ 'h', 'e', 'l', 'l', 'o' ]
  console.log(Array.from(new Set(['a', 'b']))) // [ 'a', 'b' ]
  console.log(Array.from({length: 3})) //[ undefined, undefined, undefined ]
}

{
  let set = new Set([1, 2, 3])
  const newArray = Array.from(set, x => x ** 3)
  console.log('newArray', newArray) // newArray [ 1, 8, 27 ]
}

{
  console.log(Array.of(3, 11, 8)) // [ 3, 11, 8 ]
  console.log(Array.of(3)) // [ 3 ]
  console.log(Array.of()) // []
}

{
  let arr = [1, 5, 10, 15]
  var finder = arr.find(value => value > 5)
  console.log('finder', finder) // 10

  let indexer = arr.findIndex(value => value > 5)
  console.log('indexer', indexer) // 2
}

{
  console.log([1, 2, 3].includes(2)) // true
  console.log([1, 2, 3].includes(4)) // false
  console.log([1, 2, NaN].includes(NaN)) // true
}